﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Buy2Site.MasterPages;


namespace Buy2Site.UserControls
{
    public partial class LoggedInUserAdvertise : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {            
            if (Session["User"] != null)
            {
                lblLoggedInUserName.Text = ((User)Session["User"]).FirstName + " " + 
                                            ((User)Session["User"]).LastName;
            }

        }

        protected void btnAdvertiseAd_Click(object sender, EventArgs e)
        {
            // advertise ad
            Response.Redirect("PublishItemPage.aspx");

            //TODO - fix this - need to have confirmation message with link - check if this works
            ClientScriptManager scriptManage = Page.ClientScript;
            string strConfirm = "<script>if(!window.confirm('Ad was successfully advertised'))"+
                                "{window.location.href='~/Pages/Home.aspx'}</script>";
            scriptManage.RegisterClientScriptBlock(this.GetType(), "Confirm", strConfirm, false);

            //btnAdvertiseAd.Attributes.Add("onclick", "return confirm('Ad was successfully advertised'); + ~/Pages/Home.aspx");
            //Response.Redirect("~/Pages/Home.aspx");
        }

        protected void logOut_Click(object sender, EventArgs e)
        {
            // fix log out - fixed
            Request.Cookies.Remove("userCookie");
            Session["User"] = null;
            ((MySiteMaster)Page.Master).LogInVisible = true;
            ((MySiteMaster)Page.Master).HelloUserVisible = false;
            Response.Redirect("HomePage.aspx"); // ~/Pages/HomePage.aspx
        } 
    }
}